package cn.signalpha.modules.com.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.com.entity.UserTag;
import cn.signalpha.modules.com.mapper.UserTagMapper;
import cn.signalpha.modules.com.vo.UserTagVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class UserTagService extends ServiceImpl<UserTagMapper, UserTag> {

	/**
	 * 自定义分页
	 */
    public IPage<UserTagVO> selectUserTagPage(IPage<UserTagVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectUserTagPage(page, params));
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<UserTag> selectUserTagWrapper(Map<String, Object> params) {
        QueryWrapper<UserTag> wrapper = Wrappers.query();
		wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("id")), UserTag::getId, params.get("id"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("status")), UserTag::getStatus, params.get("status"));
        wrapper.lambda().like(ObjectUtil.isNotEmpty(params.get("name")), UserTag::getName, params.get("name"));
        wrapper.lambda().orderByDesc(UserTag::getSort).orderByDesc(UserTag::getId);
        return wrapper;
    }

}

